package bancosys.tec.persist.span;

import java.util.Comparator;

/**
 * @created Mar 2, 2007
 * @author Rafael Volpato
 */
public class SpanAwareBeanComparator implements Comparator<SpanAwareBean> {

    /**
     * Compara as <code>dataInicio</code> dos beans passados como parametro.
     * 
     * @param bean1 primeiro bean.
     * @param bean2 segundo bean.
     * @return <code>-1</code> caso a <code>dataInicio</code> do <code>bean1</code> for <b>menor</b> que a <code>dataInicio</code> do
     * <code>bean2</code>, <code>1</code> se for <b>maior</b> e <code>0</code> se for <b>igual</b>.
     * @see Comparator#compare(Object, Object)
     */
    public int compare(SpanAwareBean bean1, SpanAwareBean bean2) {

        if (bean1.getDataInicio().before(bean2.getDataInicio())) {
            return -1;

        } else if ((bean1.getDataInicio().after(bean2.getDataInicio()))) {
            return 1;

        } else {
            // As duas datas são iguais
            return 0;
        }
    }
}
